layui.use(['element','laydate','form','table'], function(){

    var form = layui.form;
    setTimeout(function (){
        form.render('select');
    }, 500);

    var table = layui.table;


    var startTime = '2000-01-01';
    var endTime = '3000-01-01';
    var orderStatus = [5];
    table.render({
        elem: '#finish'
        ,toolbar: '#toolbarDemo'
        ,method : 'post'
        ,contentType : "application/json;charset=utf-8"
        ,url: '/copOrder/statement'
        ,page: false
        ,where: {
            startTime,endTime,orderStatus
        }
        ,id: 'finish'
        ,cols: [[ //表头
            {field: 'orderId',title: '订单编号', sort: true, width:120}
            ,{field: 'clientName',title: '客户名', width:120}
            ,{field: 'orderTotalPrice',title: '订单总价', width:120}
            ,{field: 'orderStartTime', title: '订单创建时间'}
            ,{field: 'orderUpdateTime', title: '订单更新时间'}
            ,{field: 'orderStatusName', title: '订单状态'}
            ,{field: 'userTrueName',title: '订单负责人'}
            ,{fixed: 'right',align:'center', toolbar: '#barDemo',title: '操作', width:120}
        ]]
    });
    var orderStatus = [1,2,3,4];
    table.render({
        elem: '#selling'
        ,toolbar: '#toolbarDemo'
        ,method : 'post'
        ,contentType : "application/json;charset=utf-8"
        ,url: '/copOrder/statement'
        ,page: false
        ,where: {
            startTime,endTime,orderStatus
        }
        ,id: 'selling'
        ,cols: [[ //表头
            {field: 'orderId',title: '订单编号', sort: true, width:120}
            ,{field: 'clientName',title: '客户名', width:120}
            ,{field: 'orderTotalPrice',title: '订单总价', width:120}
            ,{field: 'orderStartTime', title: '订单创建时间'}
            ,{field: 'orderUpdateTime', title: '订单更新时间'}
            ,{field: 'orderStatusName', title: '订单状态'}
            ,{field: 'userTrueName',title: '订单负责人'}
            ,{fixed: 'right',align:'center', toolbar: '#barDemo',title: '操作', width:120}
        ]]
    });
    var orderStatus = [0];
    table.render({
        elem: '#fail'
        ,toolbar: '#toolbarDemo'
        ,method : 'post'
        ,contentType : "application/json;charset=utf-8"
        ,url: '/copOrder/statement'
        ,page: false
        ,where: {
            startTime,endTime,orderStatus
        }
        ,id: 'fail'
        ,cols: [[ //表头
            {field: 'orderId',title: '订单编号', sort: true, width:120}
            ,{field: 'clientName',title: '客户名', width:120}
            ,{field: 'orderTotalPrice',title: '订单总价', width:120}
            ,{field: 'orderStartTime', title: '订单创建时间'}
            ,{field: 'orderUpdateTime', title: '订单更新时间'}
            ,{field: 'orderStatusName', title: '订单状态'}
            ,{field: 'userTrueName',title: '订单负责人'}
            ,{fixed: 'right',align:'center', toolbar: '#barDemo',title: '操作', width:120}
        ]]
    });

    //工具栏监听事件--详情
    table.on('tool(test)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;
        var id = obj.data.orderId;
        if(layEvent === 'detail'){
            window.location.href="OrderDetail.html?#"+id
        }
    });

});


var vm = new Vue({
    el: '#app',
    data: {
        startTime : '',
        endTime : '',
    },
    created() {
    },
    methods: {
        getAllProduct() {
            $.ajax({
                type: "get",
                url: "/copProduct/list",
                headers: {'Content-Type': 'application/json;charset=utf-8'},
                dataType: 'json',
                async: true,
                data: {},
                success: function (result) {
                    if (result.code == 500) {
                        layer.msg(result.msg)
                    } else {
                        vm.productId = result.data[0].productId;
                        vm.productList = result.data;
                    }
                }
            });
        },
        search() {
            $('#searchFrom').hide();
            $('#searchTable').show();
            var startTime = vm.startTime;
            var endTime = vm.endTime;
            //执行重载
            var table = layui.table;
            table.reload('finish', {
                where: {
                    startTime,endTime
                }
            });
            table.reload('selling', {
                where: {
                    startTime,endTime
                }
            });
            table.reload('fail', {
                where: {
                    startTime,endTime
                }
            });
        },
        back(){
            $('#searchFrom').show();
            $('#searchTable').hide();
        }
    },
})